<template>
  <el-card class="box-card" :body-style="{ padding: '20px', margin: '10px 0' }">
    <div slot="header" class="clearfix">
      <span class="card-title">{{ title }}</span>
      <el-button type="default" class="toggle-button" @click.stop="toggleCard">
        {{ isCollapsed ? '展开' : '折叠' }}
      </el-button>
    </div>
    <el-divider></el-divider>
    <div v-if="!isCollapsed">
      <slot></slot>
    </div>
  </el-card>
</template>

<script lang="ts" setup>
import { ref } from 'vue'

const props = defineProps({
  title: String,
  defaultCollapsed: {
    type: Boolean,
    default: true
  }
})

const isCollapsed = ref(props.defaultCollapsed)

const toggleCard = () => {
  isCollapsed.value = !isCollapsed.value
}
</script>

<style scoped>
.card-title {
  font-size: 18px;
  font-weight: bold;
}

.toggle-button {
  float: right;
}

.el-divider {
  margin: 10px 0;
}
</style>